package com.zzyl.controller;


import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;

import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级相关接口")
public class NursingLevelController extends BaseController {
    @Autowired
    NursingLevelService nursingLevelService;

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult deleteNursingLevel(@PathVariable Long id) {
        nursingLevelService.delete(id);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult findById(@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.findById(id);
        return success(nursingLevelVo);
    }


    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult insert(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.insert(nursingLevelDto);
        return success();
    }
    //查询所有护理等级
    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> getNursingLevelList() {

        return ResponseResult.success(nursingLevelService.getNursingLevelList());
    }

    //条件分页查询
    @GetMapping("/listByPage")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult getNursingLevelListByPage(@RequestParam(value = "name", required = false) String name,
                                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                    @RequestParam(value = "status", required = false) Integer status) {
        PageResponse<NursingLevelVo> response = nursingLevelService.getNursingLevelListByPage(name, pageNum, pageSize, status);
        return ResponseResult.success(response);

    }

    //启用禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult updateNursingLevelStatus(@PathVariable("id") Integer id, @PathVariable("status") Integer status) {
        nursingLevelService.updateNursingLevelStatus(id, status);
        return ResponseResult.success();

    }
}
